package com.inet.p11_notification;

import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.NotificationCompat;

import android.app.Notification;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Intent;
import android.graphics.BitmapFactory;
import android.graphics.Color;
import android.os.Bundle;
import android.util.Log;
import android.view.View;

import static com.inet.p11_notification.R.drawable.clock;

public class MainActivity extends AppCompatActivity {

    private static final String TAG = "elink";
    private NotificationManager manager;
    private Notification notification;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);

        if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
            NotificationChannel channel = new NotificationChannel("wz", "测试通知", NotificationManager.IMPORTANCE_HIGH);
            manager.createNotificationChannel(channel);
        }

//        notification = new NotificationCompat.Builder(this, "wz")
//                .setContentTitle("重要通知")
//                .setContentText("今天是情人节，还不赶快下班!!!")
//                .setSmallIcon(R.drawable.heart)
//                .build();
        //以上是必须设置的

        Intent intent = new Intent(this, NotifyActivity.class);
        PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, 0);


        notification = new NotificationCompat.Builder(this, "wz")
                .setContentTitle("重要通知")
                .setContentText("今天是情人节，还不赶快下班!!!")
                .setSmallIcon(R.drawable.heart)
                .setLargeIcon(BitmapFactory.decodeResource(getResources(), clock))
                .setColor(Color.parseColor("#ff0000"))
                .setContentIntent(pendingIntent)
                .setAutoCancel(true)
//                .setWhen(System.currentTimeMillis()+5000)
                .build();

    }

    public void sendNotify(View view) {
        manager.notify(110, notification);


    }


    public void cancelNotify(View view) {
        manager.cancel(110);
    }


    public void touchView(View view) {
        Log.d(TAG, "touchView: 点击了背景View");
    }


}